package com.jcfk.eam.controller.mould;

import cn.hutool.core.util.StrUtil;
import com.jcfk.common.business.enums.AvailableStatus;
import com.jcfk.common.business.log.annotation.RequestLogHeader;
import com.jcfk.common.business.utils.DataBindHelper;
import com.jcfk.common.web.domain.DataPage;
import com.jcfk.common.web.domain.ReqPageParam;
import com.jcfk.common.web.domain.RetPage;
import com.jcfk.common.web.domain.RetResult;

import com.jcfk.eam.domain.dto.mould.EamMouldEmailRecordDTO;
import com.jcfk.eam.domain.dto.mould.EamMouldEmailRecordDetailDTO;
import com.jcfk.eam.domain.query.mould.EamMouldEmailRecordQuery;
import com.jcfk.eam.service.mould.EamMouldEmailRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.validation.Valid;


import java.util.List;

/**
 * 模具寿命邮件发送记录主表
 *
 * @author yrl
 * @email 
 * @date 2025-07-28
 */
@Api(tags = {"模具寿命邮件发送记录主表管理"})
@RestController
@RequestMapping("eammouldemailrecord")
public class EamMouldEmailRecordController {
    @Autowired
    private EamMouldEmailRecordService eamMouldEmailRecordService;

    /**
     * 分页列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "ReqPageParam<EamMouldEmailRecordQuery>", name = "requestParam", value = "", required = true)
    })
    @ApiOperation("分页查询模具寿命邮件发送记录主表")
    @PostMapping("/queryByPage")
    public RetPage<EamMouldEmailRecordDTO> queryByPage(@RequestBody ReqPageParam<EamMouldEmailRecordQuery> requestParam) {
        DataPage<EamMouldEmailRecordDTO> page = new DataPage<EamMouldEmailRecordDTO>((long) requestParam.getCurrent(),
                (long) requestParam.getSize(),
                requestParam.getSort().getOrderItem(),
            EamMouldEmailRecordDTO.class);
        page = eamMouldEmailRecordService.queryByPage(page, requestParam.getData());

        return new RetPage<>(page);
    }


    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamMouldEmailRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取模具寿命邮件发送记录主表列表", notes = "获取模具寿命邮件发送记录主表列表", httpMethod = "POST")
    @PostMapping("getDetails")
    public RetResult<List<EamMouldEmailRecordDetailDTO>> getDetails(@RequestBody EamMouldEmailRecordQuery query) {

        List<EamMouldEmailRecordDetailDTO> list = eamMouldEmailRecordService.getDetails(query);

        return RetResult.ok(list);
    }

    /**
     * 获取信息列表
     *
     * @param query
     * @return
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", dataType = "EamMouldEmailRecordQuery", name = "query", value = "", required = true)
    })
    @ApiOperation(value = "获取模具寿命邮件发送记录主表列表", notes = "获取模具寿命邮件发送记录主表列表", httpMethod = "POST")
    @PostMapping("getList")
    public RetResult<List<EamMouldEmailRecordDTO>> getList(@RequestBody EamMouldEmailRecordQuery query) {

        List<EamMouldEmailRecordDTO> list = eamMouldEmailRecordService.getList(query);

        return RetResult.ok(list);
    }


    /**
     *  模具寿命邮件发送记录主表
     * 根据id 查询详情
     */
    @ApiOperation("查询模具寿命邮件发送记录主表")
    @GetMapping("/getDetail/{id}")
    public RetResult<EamMouldEmailRecordDTO> getDetail(@PathVariable("id") String id) {
        EamMouldEmailRecordDTO item = eamMouldEmailRecordService.getDetail(id);
        return RetResult.ok(item);
    }

    /**
     *  模具寿命邮件发送记录主表
     * 根据id 查询详情
     */
    @ApiOperation("查询模具寿命邮件发送记录主表")
    @GetMapping("/get/{id}")
    public RetResult<EamMouldEmailRecordDTO> get(@PathVariable("id") String id) {
            EamMouldEmailRecordDTO item = eamMouldEmailRecordService.get(id);
        return RetResult.ok(item);
    }

    /**
     * 添加/更新管理模具寿命邮件发送记录主表
     */
    @ApiOperation("保存模具寿命邮件发送记录主表")
    @PostMapping("/save")
    @RequestLogHeader(modular = "模具寿命邮件发送记录主表管理", businessType = "保存")
    public RetResult<?> save(@RequestBody @Valid EamMouldEmailRecordDTO eamMouldEmailRecord) {
        // 数据校验
        RetResult ret = eamMouldEmailRecordService.isValid(eamMouldEmailRecord);
        if (!ret.getCode().equals(RetResult.SUCCESS)) {
            return ret;
        }

        if (StrUtil.isEmpty(eamMouldEmailRecord.getId())){
            // 新增
                eamMouldEmailRecordService.insert(eamMouldEmailRecord);
        } else{
            // 更新
                eamMouldEmailRecordService.update(eamMouldEmailRecord);
        }
        return RetResult.ok();

    }


    /**
     *  批量删除模具寿命邮件发送记录主表
     */
    @ApiOperation("批量删除模具寿命邮件发送记录主表")
    @PostMapping("/delete")
    @RequestLogHeader(modular = "模具寿命邮件发送记录主表管理", businessType = "批量删除")
    public RetResult<?> delete(@RequestBody EamMouldEmailRecordDTO eamMouldEmailRecord) {
        return RetResult.ok(eamMouldEmailRecordService.logicDeleteList(eamMouldEmailRecord));
    }


    /**
     *  删除模具寿命邮件发送记录主表
     */
    @ApiOperation("删除模具寿命邮件发送记录主表")
    @PostMapping("/deleteItem/{id}")
    @RequestLogHeader(modular = "模具寿命邮件发送记录主表管理", businessType = "删除")
    public RetResult<?> deleteItem(@PathVariable("id") String id) {
        eamMouldEmailRecordService.deleteItem(id);
        return RetResult.ok();
    }
}
